package grape.wx.rest.mp.basic.mvc;

import grape.common.exception.ExceptionCode;
import grape.common.exception.ExceptionTools;
import grape.common.exception.runtime.InvalidParamsException;
import grape.common.rest.advice.DisableGRB;
import grape.common.rest.advice.DisableGRM;
import grape.common.rest.mvc.SuperController;
import grape.wx.service.mp.MpProperties;
import grape.wx.service.mp.user.api.IMpUserService;
import grape.wx.service.mp.user.po.MpUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpMessageRouter;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
import me.chanjar.weixin.mp.bean.result.WxMpUser;
import me.chanjar.weixin.mp.util.WxMpConfigStorageHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * Created by yangwei
 * Created at 2020/7/20 20:48
 */
@Slf4j
@RestController
@RequestMapping("/wx/mp/oauth2/{appId}")
@Api(tags = "公众号oauth2相关接口")
public class MpOAuth2Controller extends SuperController {

    @Autowired
    private WxMpService wxMpService;
    @Autowired
    private IMpUserService iMpUserService;
    @Autowired
    private MpProperties mpProperties;

    @ApiOperation("构造网页授权url")
    @ResponseStatus(HttpStatus.OK)
    @GetMapping("/oauth2buildAuthorizationUrl")
    public String oauth2buildAuthorizationUrl(@PathVariable String appId,
                       @Valid @RequestParam String url) {
        wxMpService.switchover(appId);
        String rUrl = wxMpService.oauth2buildAuthorizationUrl(url, WxConsts.OAuth2Scope.SNSAPI_USERINFO, null);
        return  rUrl;
    }
}
